package com.mao;

import java.util.Scanner;

public class ArrayDemo2 {
    public static void main(String[] args) {
        //动态定义数组
        inputScore();
    }
    //设计一个方法录入学生成绩
    public static void inputScore(){
        //定义一个数组，存储学生成绩
        double[] scores = new double[8];
        //scores = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
        //录入学生成绩
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入第"+(i+1)+"个学生的成绩：");
            //每访问到一个元素，就让用户输入一个成绩
            scores[i] = sc.nextDouble();
        }
        //遍历数组，统计总分，统计最高分，最低分
        double allScore = 0.0;
        double maxScore = scores[0];
        double minScore = scores[0];
        for (int i = 0; i < scores.length; i++) {
            double score = scores[i];
            //累加当前遍历到的这个分数
            allScore += score;
            //找到最高分
            if(score>maxScore){
                maxScore = score;
            }
            //找到最低分
            if(score<minScore){
                minScore = score;
            }
        }
        System.out.println("平均分："+ allScore/scores.length);
        System.out.println("最高分："+ maxScore);
        System.out.println("最低分："+ minScore);

    }
}
